package com.lzw.breezeNovel.webApp.service.impl.user;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.lzw.breezeNovel.webApp.service.common.SmsService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.service.novel.impl
 * @date 2025/2/27
 * @description 发送验证码
 */
@Service
@SuppressWarnings("all")
public class SmsServiceImpl implements SmsService {

    // 注入短信服务客户端
    @Autowired
    private Client client;

    /**
     * 发送验证码
     * @param phone
     * @param code
     */
    @SneakyThrows
    @Override
    public void sendCode(String phone, String code) {
        // 创建短信发送请求对象
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        // 设置接收验证码的手机号码
        sendSmsRequest.setPhoneNumbers(phone);
        // 设置短信签名名称
        sendSmsRequest.setSignName("阿里云短信测试");
        // 设置短信模板编号
        sendSmsRequest.setTemplateCode("SMS_154950909");
        // 设置短信模板参数，将验证码作为参数传入
        sendSmsRequest.setTemplateParam("{\"code\":\"" + code + "\"}");
        // 发送短信
        client.sendSms(sendSmsRequest);
    }
}
